package indi.gao.leetcode.problem;

import java.util.Arrays;

/**
 * <p>Description:</p>
 * <p>person: gaolei</p>
 * <P>Created Date :2020$-03$-31$</P>
 */
public class SortArray912 {
    public static void main(String[] args) {
        int[] ints = {7, 8, 10, 2, 64, 5, 6, 53, 5, 4654, 465, 465, 78, 345, 7, 46, 67};
        // Solution solution = new Solution();
        // System.out.println(Arrays.toString(solution.sortArray(ints)));

        //bubble test
        // Bubble(ints);
        quickSort(ints, 0, ints.length - 1);
        for (int num : ints) {
            System.out.print(num + ">");
        }
    }

    /**
     * @throws Exception
     * @Description:冒泡排序
     * @create: 2020/4/9 22:46
     * @update logs
     */
    public static void Bubble(int[] nums) {

        // 需要进行n-1次冒泡
        for (int i = 1; i < nums.length; i++) {
            //
            for (int j = 1; j <= nums.length - i; j++) {
                if (nums[j] < nums[j - 1]) {
                    // 交换位置
                    int swap = nums[j];
                    nums[j] = nums[j - 1];
                    nums[j - 1] = swap;
                }
            }
        }
        for (int num : nums) {
            System.out.print(num + ">");
        }
    }

    /**
     * @throws Exception
     * @Description:quickSort
     * @create: 2020/4/10 22:09
     * @update logs
     */
    public static void quickSort(int[] nums, int left, int right) {
        if (left >= right) {
            return;
        }
        int temp = nums[left];
        int leftTemp = left;
        int rightTemp = right;
        while (rightTemp > leftTemp) {
            while (nums[rightTemp] >= temp && rightTemp > leftTemp) {
                rightTemp--;
            }
            nums[leftTemp] = nums[rightTemp];
            while (nums[leftTemp] <= temp && rightTemp > leftTemp) {
                leftTemp++;
            }
            nums[rightTemp] = nums[leftTemp];
        }
        nums[leftTemp] = temp;
        quickSort(nums, left, leftTemp - 1);
        quickSort(nums, leftTemp + 1, right);
    }

    /**
     * @throws Exception
     * @Description merge sort
     * @create: 2020/4/14 14:31
     * @update logs
     */
    private void mergeSort(int nums[]) {

    }
}

class Solution {
    public int[] sortArray(int[] nums) {
        Arrays.sort(nums);
        return nums;
    }
}
